#include <iostream>

using namespace std;

int l, r, L, R, k;

bool check(int x, int sys)
{
	int a = x % sys; x /= sys;
	cout << a << endl;
	if(x == 0) return true;
	int b = x % sys; x /= sys;
	cout << b << endl;
	if(a == b) return false;
	int pos = 3;
	while(x)
	{
		int y = x % sys; x /= sys;
		if(pos % 2 == 1 && y != a) return false;
		if(pos % 2 == 0 && y != b) return false;
	}
	return true;
}

int main()
{
	cin >> l >> r >> L >> R >> k;
	for(int i = 191919; i <= 191919; i++)
	{
		int cnt = 0;
		for(int j = l; j <= l; j++)
		{
			if(check(i, j)) cnt++;
			if(cnt > k) break; 
		}
		if(cnt == k) cout << i << endl;
	}
	return 0;
}
